﻿#region  文件信息
// ---------------------------------------------------------------------------------------
// <copyright file="TxtFile.cs" company="">
// 作者：李帅伦
// </copyright>
// <summary>
// 类型简介：
// 类型详细：TxtFile.cs
// 创建时间：2014-08-25 11:44
// 修改时间：2014-08-25 11:44
// </summary>
// ---------------------------------------------------------------------------------------
#endregion
namespace WebCommon.IO
{
    using System;
    using System.IO;
    using System.Text;

    public class TxtFile 
    {
       
 

        public TxtFile()
        {
            
        }
        /// <summary>
        /// 写入文件
        /// </summary>
        /// <param name="path">路径</param>
        /// <param name="str">内容</param>
        public static void Write(string path,string str)
        { 
             
            FileOperation.CreateDirectory(path);
            using (var fs = new FileStream(path, FileMode.Create, FileAccess.Write))
            {
                using (var sw = new StreamWriter(fs, Encoding.UTF8))
                {
                    //开始写入
                    sw.Write(str); 
                }
            } 
        }
        /// <summary>
        /// 读取文件
        /// </summary>
        /// <param name="path">路径</param>
        /// <returns></returns>
        public static string Read(string path )
        {
            using (var sr = new StreamReader(path, Encoding.UTF8))
            { 
                String line;
                var sb = new StringBuilder();
                while ((line = sr.ReadLine()) != null)
                {
                    sb.Append(line);
                }

                return sb.ToString();
            }
        }
      
    }
}